<%-- internal/maintain/delivery/index.jsp --%>

<?xml version="1.0" encoding="UTF-8"?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="problemDomain.EmployeeAccountBean, problemDomain.EmployeeAccountBean.Position" %>   

<%

//get the currently logged on employee from session
EmployeeAccountBean employee = (EmployeeAccountBean)session.getAttribute("employee");
EmployeeAccountBean.Position pos = null;
if (employee != null)
	pos = employee.getPosition();
else {
	response.sendRedirect("../../login/");
	return;
}

if (pos != Position.MANAGER && pos != Position.HOST) {
	response.sendRedirect("../../login/");
	return;
}

int deliveryID = 0;
String str = (String)request.getParameter("deliveryID");
if (str != null)
	deliveryID = Integer.parseInt(str);

int orderID = 0;
String firstname = "";
String lastname = "";
String phone = "";
String sOrderID = (String)request.getParameter("orderID");
if (sOrderID != null) {
	orderID = Integer.parseInt(sOrderID);
	firstname = (String)request.getParameter("firstname");
	lastname = (String)request.getParameter("lastname");
	phone = (String)request.getParameter("phone");
}
%>

   
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="problemDomain.EmployeeAccountBean"%>
<%@page import="problemDomain.EmployeeAccountBean.Position"%><html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<link type="text/css" rel="stylesheet" href="../../css/general.css" />
		<link type="text/css" rel="stylesheet" href="../../css/framed.css" />
		<link type="text/css" rel="stylesheet" href="../../css/delivery/form.css" />
		<script type="text/javascript" src="../../js/ajax-handler.js"></script>
		<script type="text/javascript" src="../../js/form.js"></script>
		<script type="text/javascript" src="../../js/dialog.js"></script>
		<script type="text/javascript" src="../../js/delivery/form.js"></script>
		<script type="text/javascript" src="../../js/delivery/maintain.js"></script>
		<title>ORDRS - Maintain Delivery</title>
		
		<script>
			var deliveryID = <% out.print(deliveryID + ";"); %>
			if (deliveryID > 0)
				reportDelivery(deliveryID);
		</script>
	</head>
	
	<body onload="loadPage()">
		<!-- Title -->
			<div class="pageTitle">
				<img src="../../images/logo.bmp" />
				<!-- Logout -->
				<div class="navi">
					<table class="navi" align="right">
					<tr>
					<% 
					// Display the links according to the employee's position
					if (pos != null){
						if (pos == EmployeeAccountBean.Position.MANAGER) {
							out.println("<td class=\"navi\"><a href=\"../employee/index.jsp \">Employee</a></td>");
							out.println("<td class=\"navi\"><a href=\"../food-item/index.jsp\">Food Item</a></td>");
							out.println("<td class=\"navi\"><a href=\"../menu/index.jsp\">Menu</a></td>");
							out.println("<td class=\"navi\"><a href=\"../menu-item/index.jsp\">Menu Item</a></td>");
							out.println("<td class=\"navi\"><a href=\"../../view/report/index.jsp\">Report</a></td>");
						}
							out.println("<td class=\"navi\"><a href=\"../order/index.jsp\">Order</a></td>");
							out.println("<td class=\"navi\"><a href=\"../reservation/\">Reservation</a></td>");
					}
					%>
					<td class="navi"><a href="../../login/">Logout</a></td>
						</tr>
					</table>
				</div>
				<!-- END Logout -->
			</div>
			<!-- END Title -->
		
		<!-- Panel -->
		<div class="panel">
		<fieldset>
			<legend style="font-size: 36px;">Maintain Delivery</legend>
			<table style="border: 0px; width: 100%;">
				<tr style="height: 100%">
					<td rowspan="2">
						<!-- Fields -->
						<div class="fields">
						<input id="deliveryID" type="hidden" value=""/>
						<input id="orderID" type="hidden" value="<% out.print(orderID); %>"/>
							<table style="border-collapse: collapse">
								<tr>
									<td><h4>Receiver Info</h4></td>
								</tr>
								<tr>
									<td class="fieldLabel">* First Name:</td>
									<td><input id="firstname" type="text" maxlength="30" value="<% out.println(firstname); %>"/></td>
									<td id="firstnameMessage"></td>
								</tr>
								<tr>
									<td class="fieldLabel">Last Name:</td>
									<td><input id="lastname" type="text" maxlength="30" value="<% out.println(lastname); %>" /></td>
									<td id="lastnameMessage"></td>
								</tr>
								<tr>
									<td class="fieldLabel">* Phone No.:</td>
									<td><input id="phone" type="text" maxlength="10" value="<% out.println(phone); %>"/></td>
									<td id="phoneMessage"></td>
								</tr>
								<tr>
									<td><h4>Delivery Info</h4></td>
								</tr>
								<tr>
									<td class="fieldLabel">* Address:</td>
									<td><input id="address" type="text" maxlength="40"/></td>
									<td id="addressMessage"></td>
								</tr>
								<tr>
									<td class="fieldLabel">* City:</td>
									<td><input id="city" type="text" maxlength="30"/></td>
									<td id="cityMessage"></td>
								</tr>
								<tr>
									<td class="fieldLabel">* Province:</td>
									<td><input id="province" type="text" maxlength="2"/></td>
									<td id="provinceMessage"></td>
								</tr>
								<tr>
									<td class="fieldLabel">Postal Code:</td>
									<td><input id="postalCode1" type="text" maxlength="3" />
										<input id="postalCode2" type="text" maxlength="3" /></td>
									<td id="postalCodeMessage"></td>
								</tr>
								<tr>
									<td class="fieldLabel">* Dwelling Type:</td>
									<td>
										<select id="dwellingType" onchange="showHideInputBox()">
										<option value="" selected="selected"></option>
											<optgroup id="dwellingTypeOptGroup" label="Dwelling Type">
											</optgroup>
										</select>
									</td>
									<td id="dwellingTypeMessage"></td>
								</tr>
								<tr id="buildingTR">
									<td class="fieldLabel" id="buildingLabel">Buidling Name:</td>
									<td><input id="building" type="text" maxlength="50" /></td>
									<td id="buildingMessage"></td>
								</tr>
								<tr id="roomTR">
									<td class="fieldLabel" id="roomLabel">Room No.:</td>
									<td><input id="room" type="text" maxlength="5" /></td>
									<td id="roomMessage"></td>
								</tr>
								<tr>
									<td class="fieldLabel">* Delivery Status:</td>
									<td>
										<select id="deliveryStatus">
											<optgroup id="deliveryStatusOptGroup" label="Delivery Status">
											</optgroup>
										</select>
										<input id="deliveryStatusType" style="display: none;" type="text" />
									</td>
									<td id="deliveryStatusMessage"></td>
								</tr>
								<tr>
									<td class="fieldLabel">Instruction:</td>
									<td><textArea id="instruction" type="text" maxlength="225" wrap="soft"></textArea></td>
									<td id="instructionMessage"></td>
								</tr>
							</table>
						</div>
						<!-- END Fields -->
					</td>
					<td rowspan="2" class="vrule"></td>
					<td class="resultsHead">Results
						<table>
							
							<tr>
							<form name="showOpForm">
								<td><input type="radio" name="showOption" value="0" onclick="listAllDelivery()"/>All Deliveries</td>	
								<td><input type="radio" name="showOption" value="1" onclick="listAllDelivery()"/>Incomplete Deliveries</td>	
							</form>
								
							</tr>
						</table>
					</td>
					<td text-align="right">
						<!-- List All Button -->
						<ul class="toolbar">
							<li onclick="listAllDelivery()">List All</li>
						</ul>
					</td>
				</tr>
				<tr>
					<td class="resultsTD" colspan="2">
						<!-- Results -->
						<div id="results" class="results">
						</div>
						<!-- END Results -->
					</td>
				</tr>
				<tr>
					<td>
						<!-- Toolbar -->
						<ul class="toolbar">
							<li onclick="reportDelivery()">Search</li>
							<li onclick="updateDelivery()">Update</li>
							<li onclick="deleteDelivery()">Delete</li>
							<li onclick="resetFields()">Clear</li>
						</ul>
						<!-- END Toolbar -->
					</td>
					<td colspan="3">Search can be performed by First Name, Last Name and/or Phone No.</td>
					<td class="rightAligned">
						
					</td>
				</tr>
			</table>
		</fieldset>
		</div>
		<!-- END Panel -->
		<br />
		<br />
	</body>
</html>
